Page({
  data: {
    isLike: true,
    current: 0,
    // banner
    imgUrls: [
      "/assets/主图@2x.png",
      "/assets/所有项目3@2x.png",
      "/assets/所有项目5@2x.png",
      "/assets/所有项目6@2x.png",
      "/assets/所有项目2@2x.png"
    ],
    indicatorDots: true, //是否显示面板指示点
    autoplay: true, //是否自动切换
    interval: 3000, //自动切换时间间隔,3s
    duration: 1000, //  滑动动画时长1s
    flowerImgSelect: '/assets/为你推荐@2x.png', //选中的花色图片
    flowerNameSelect: "", //
    flowerSelect: 0, //判断是否选中
    isHidden: 0,
    showModalStatus: false, //显示遮罩
    goodNum: 0, //商品数量
    select: 0, //商品详情、参数切换
    // 商品详情介绍
    detailImg: [
      "/assets/未标题-1_01.png",
      "/assets/未标题-1_02.png",
      "/assets/未标题-1_03.png",
      "/assets/未标题-1_04.png"
    ],
    swiperchange(e) {
      this.setData({
        current: e.detail.current,
      })
    },
    fuwu: false,
    animationData: {},
    orinGoodMsg: {
      "good": {
        "good_display_img": "",
      },
      "goodflowers": [{
        "flower_name": "A套餐",
        "flower_id": "11d75c6a560a4345b232706f7642de22",
        "flower_image": "/assets/为你推荐@2x.png",
        "good_id": "17",
        "flower_identity": ""
      }, {
        "flower_name": "B套餐",
        "flower_id": "3994afdb0427425d93bbba6e881601c3",
        "flower_image": "",
        "good_id": "17",
        "flower_identity": ""
      }],
      "roleType": "2",
      "isAdmin": true
    },
    good: { //商品

    },
    mainImg: '', //主图
    goodPrice: 99.99, //商品价格
    goodOrinPrice: 999.99,
    goodflowers: [


    ],
    chooseFlowers: [ //选中的花色

    ],

  },
  toPingjia: function () {
    wx.navigateTo({
      url: '/pages/pingjia/pingjia'
    })
  },
  toPay: function () {
    wx.navigateTo({
      url: '/pages/pay/payfalse/payfalse'
    })
  },
  onLoad: function (options) {
    var that = this;

    var data = that.data.orinGoodMsg; //写死的商品信息
    var goodBaseMsg = data.good; //商品基本信息
    var goodflowersMsg = data.goodflowers; //商品花色信息
    var goodPrice = 999.99; //显示价格
    var goodOrinPrice = 999.99; //划线价格
    for (var i = 0; i < goodflowersMsg.length; i++) {
      var jo = {
        flower_image: goodflowersMsg[i].flower_image,
        flower_id: goodflowersMsg[i].flower_id,
      }
    };
    that.setData({ //商品
      mainImg: goodBaseMsg.good_display_img,
      flowerImgSelect: goodBaseMsg.good_display_img,
      good: goodBaseMsg,
      goodflowers: goodflowersMsg,
      goodPrice: goodPrice,
      goodOrinPrice: goodOrinPrice,

    });
    if (wx.hideLoading()) {
      wx.hideLoading()
    }
    




  },
  /**选择花色 */
  chooseFlower: function (data) {
    var that = this;
    var flower_id = data.currentTarget.dataset.select;
    var flower_name = data.currentTarget.dataset.flowerName;

    that.setData({ //把选中值，放入判断值中
      flowerNameSelect: flower_name,
      flowerSelect: flower_id
    })
    var str = flower_id + ',' + flower_name;
    var chooseFlowers = that.data.chooseFlowers;
    chooseFlowers = [];
    chooseFlowers.push(str);
    that.setData({
      chooseFlowers: chooseFlowers,
      flowerImgSelect: data.currentTarget.dataset.img
    })

  },

  /**选择花色 */
  chooseFlower: function (data) {
    var that = this;
    var flower_id = data.currentTarget.dataset.select;
    var flower_name = data.currentTarget.dataset.flowerName;

    that.setData({ //把选中值，放入判断值中
      flowerNameSelect: flower_name,
      flowerSelect: flower_id
    })
    var str = flower_id + ',' + flower_name;
    var chooseFlowers = that.data.chooseFlowers;
    chooseFlowers = [];
    chooseFlowers.push(str);
    that.setData({
      chooseFlowers: chooseFlowers,
      flowerImgSelect: data.currentTarget.dataset.img
    })


  },
   goodAdd: function (data) {

    var that = this;
    var goodCount = that.data.goodNum + 1;
    that.setData({ //商品数量+1
      goodNum: goodCount
    })

  },
  goodReduce: function (data) {

    var that = this;
    var goodCount = that.data.goodNum - 1;
    that.setData({ //商品数量+1
      goodNum: goodCount
    })

  },
  /**商品详情、参数切换 */
  changeArea: function (data) {
    var that = this;
    var area = data.currentTarget.dataset.area;
    that.setData({
      "select": area
    });

  },
  addCart: function (data) {
    var that = this;
    var thatData = that.data;
    var ja = thatData.chooseFlowers; //选中的花色id
    var good_id = thatData.good.good_id; //good_id
    var good_name = thatData.good.good_name; //good_name
    var gn = thatData.goodNum; //数量
    var good_price = thatData.goodPrice; //价格



    if (ja.length > 0) {
      wx.showToast({
        title: '成功！',
        duration: 2000,
      })

    } else {
      wx.showToast({
        title: '您还没有选择花色哦~',
        duration: 2000,
      })
    }



  },
  /**
   * 生成订单
   */
  saveOrder: function (data) {
    var that = this;
    var thatData = that.data;
    var ja = thatData.chooseFlowers; //选中的花色
    var good_id = thatData.good.good_id; //good_id
    var good_name = thatData.good.good_name; //good_name
    var gn = thatData.goodNum; //数量
    var good_price = thatData.goodPrice; //价格v
    var goodDisplayImg = thatData.mainImg; //主图

    if (ja.length > 0) {

      wx.showToast({
        title: '成功！',
        duration: 2000,
      })
    } else {
      wx.showToast({
        title: '您还没有选择花色哦~',
        duration: 2000,

      })

    }




  },






  //服务弹出层
  showModal: function () {
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  // 显示优惠遮罩层
  showYouhui: function () {
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showYouhuiStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
      // 显示商品遮罩层
  showShangpin: function () {
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showShangpinStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },



  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false,
        showYouhuiStatus:false,
        showShangpinStatus:false
      })
    }.bind(this), 200)
  },
  
  // 收藏
  addLike() {
    this.setData({
      isLike: !this.data.isLike
    });
  },
  // 跳到购物车
  toCar() {
    wx.switchTab({
      url: '/pages/cart/cart'
    })
  },
  toHome() {
    wx.switchTab({
      url: '/pages/index/index'
    })
  },
})